"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Processor = void 0;
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var Processor = /** @class */ (function () {
    function Processor() {
    }
    Processor.prototype.process = function (src, cfgRoot) {
        if (!fs_1.default.existsSync(cfgRoot)) {
            throw new Error("Configuration file not exists: " + cfgRoot);
        }
        var name2id = {};
        var cfgContent = fs_1.default.readFileSync(cfgRoot, 'utf-8');
        var cfgLines = cfgContent.split(/\r?\n+/);
        for (var _i = 0, cfgLines_1 = cfgLines; _i < cfgLines_1.length; _i++) {
            var cl = cfgLines_1[_i];
            var clPairs = cl.split(/\s+/);
            if (clPairs.length >= 2) {
                var id = clPairs[0], folderName = clPairs[1];
                name2id[folderName] = id;
            }
        }
        var failedList = [];
        if (fs_1.default.existsSync(src)) {
            var files = fs_1.default.readdirSync(src);
            for (var _a = 0, files_1 = files; _a < files_1.length; _a++) {
                var f = files_1[_a];
                var filePath = path_1.default.join(src, f);
                var fileStat = fs_1.default.statSync(filePath);
                if (fileStat.isDirectory()) {
                    var id = name2id[f];
                    if (id) {
                        fs_1.default.renameSync(filePath, path_1.default.join(src, id));
                    }
                    else {
                        failedList.push(f);
                    }
                }
            }
        }
        if (failedList.length) {
            console.error(failedList.length + " failed: " + failedList.join(', '));
        }
    };
    return Processor;
}());
exports.Processor = Processor;
